package com.ys.erp.entity.data.bean;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.ObjectUtils;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author lwj
 */
    
@Data
@TableName(value = "t_order")
@Accessors(chain = true)
public class Order {
    /**
     * 主键
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 订单编号
     */
    @TableField(value = "order_serial_number")
    private String orderSerialNumber;

    /**
     * 商品类型 0实物 1虚拟卡卷
     */
    @TableField(value = "goods_type")
    private Integer goodsType;

    @TableField(value = "order_attr")
    private String orderAttr;

    @TableField(value = "camp_id")
    private Long campId;

    /**
     * 用户id
     */
    @TableField(value = "user_id")
    private Long userId;

    /**
     * 下单时间
     */
    @TableField(value = "order_time")
    private LocalDateTime orderTime;

    /**
     * 订单状态：0待付款，1已付款代发货，2：已发货待收货，3：已收货, 4：已完成
     */
    @TableField(value = "order_status")
    private Integer orderStatus;

    /**
     * 是否取消，0否1是
     */
    @TableField(value = "is_cancel")
    private Integer isCancel;

    /**
     * 是否当面付订单0否1是
     */
    @TableField(value = "is_person_pay")
    private Integer isPersonPay;

    /**
     * 当面付支付门店
     */
    @TableField(value = "person_pay_shop_code")
    private String personPayShopCode;

    /**
     * 返款比列
     */
    @TableField(value = "refund_ratio")
    private String refundRatio;

    /**
     * 订单取消时间
     */
    @TableField(value = "cancel_time")
    private LocalDateTime cancelTime;

    /**
     * 取消备注
     */
    @TableField(value = "cancel_remark")
    private String cancelRemark;

    /**
     * 用户发起取消
     */
    @TableField(value = "is_user_cancel")
    private Integer isUserCancel;

    /**
     * 用户发起取消,0,用户发起取消，1已通过，2已拒绝
     */
    @TableField(value = "user_cancel_status")
    private Integer userCancelStatus;

    /**
     * 拒绝用户取消理由
     */
    @TableField(value = "user_cancel_reject_remark")
    private String userCancelRejectRemark;

    /**
     * 配送方式，0：快递配送，1：到店自提，2:自动发货
     */
    @TableField(value = "delivery_type")
    private Integer deliveryType;

    /**
     * 订单支付类型0：wx支付，1：幺币支付
     */
    @TableField(value = "pay_type")
    private String payType;

    /**
     * 幺币支付猫咪钱包
     */
    @TableField(value = "pay_cat_code")
    private String payCatCode;

    /**
     * 是否发起售后0否1是
     */
    @TableField(value = "is_after_sale")
    private Integer isAfterSale;

    /**
     * 发起售后时间
     */
    @TableField(value = "after_sale_time")
    private LocalDateTime afterSaleTime;

    /**
     * 支付时间
     */
    @TableField(value = "pay_time")
    private LocalDateTime payTime;

    /**
     * 发货时间
     */
    @TableField(value = "send_goods_time")
    private LocalDateTime sendGoodsTime;

    /**
     * 收货时间
     */
    @TableField(value = "delivery_time")
    private LocalDateTime deliveryTime;

    /**
     * 订单完成时间
     */
    @TableField(value = "complete_time")
    private LocalDateTime completeTime;

    /**
     * 支付记录id
     */
    @TableField(value = "order_pay_id")
    private String orderPayId;

    /**
     * 使用的用户优惠券id
     */
    @TableField(value = "user_coupon_id")
    private Long userCouponId;

    /**
     * 合计需支付，单位分
     */
    @TableField(value = "total_money")
    private Long totalMoney;

    /**
     * 商品总金额，单位分
     */
    @TableField(value = "goods_total_money")
    private Long goodsTotalMoney;

    /**
     * 总优惠金额，单位分
     */
    @TableField(value = "discount_money")
    private Long discountMoney;

    /**
     * 微信实际支付金额
     */
    @TableField(value = "actual_wx_money")
    private Long actualWxMoney;

    /**
     * 幺币实际支付金额
     */
    @TableField(value = "actual_ys_money")
    private Long actualYsMoney;

    /**
     * 幺豆抵扣金额
     */
    @TableField(value = "ys_pulse_money")
    private Long ysPulseMoney;

    @TableField(value = "ys_pulse_num")
    private Long ysPulseNum;

    /**
     * 实际支付，单位分
     */
    @TableField(value = "actual_money")
    private Long actualMoney;

    /**
     * 支付运费，单位分
     */
    @TableField(value = "freight_money")
    private Long freightMoney;

    /**
     * 买家备注
     */
    @TableField(value = "user_remark")
    private String userRemark;

    /**
     * 订单备注
     */
    @TableField(value = "order_remark")
    private String orderRemark;

    /**
     * 快递名称
     */
    @TableField(value = "express_name")
    private String expressName;

    /**
     * 快递单号
     */
    @TableField(value = "express_id")
    private String expressId;

    /**
     * 收货人姓名
     */
    @TableField(value = "delivery_name")
    private String deliveryName;

    /**
     * 收货人手机号
     */
    @TableField(value = "delivery_phone")
    private String deliveryPhone;

    /**
     * 收货人省 
     */
    @TableField(value = "delivery_province")
    private String deliveryProvince;

    /**
     * 收货人市
     */
    @TableField(value = "delivery_city")
    private String deliveryCity;

    /**
     * 收货人区
     */
    @TableField(value = "delivery_district")
    private String deliveryDistrict;

    /**
     * 详细收货地址
     */
    @TableField(value = "delivery_detail")
    private String deliveryDetail;

    /**
     * 是否删除
     */
    @TableField(value = "is_delete")
    private Integer isDelete;

    /**
     * 是否拉起评论弹窗 1 是 0否 默认1
     */
    @TableField(value = "is_comment")
    private Integer isComment;

    /**
     * 是否已评价 1是 0否
     */
    @TableField(value = "is_reviewed")
    private Integer isReviewed;

    @TableField(value = "version")
    @Version
    private Integer version;

    @TableField(value = "create_time")
    private LocalDateTime createTime;

    @TableField(value = "update_time", update = "now()")
    private LocalDateTime updateTime;

    public List<Long> getPayIdList() {
        if (ObjectUtils.isEmpty(this.getOrderPayId())) {
            return new ArrayList<>();
        }
        return Arrays.stream(this.getOrderPayId().split(","))
                .filter(s -> !s.trim().isEmpty())
                .map(Long::valueOf)
                .toList();
    }

}